# encoding: UTF-8

class Admin::TopicsController < ApplicationController
  before_filter :user_signed_in?
  
  def index

  end

  def new
    @category = Node.find_all_by_status(0)
    set_seo_meta '文章添加'
  end

  def create
    @topic = Topic.new(params[:session])
    if @topic.save
      redirect_to '/topics/category/1', notice: '新增成功'
    else
      redirect_referrer_or_default
    end  
  end

  def edit
    @category = Node.find_all_by_status(0)
    @topic = Topic.find(params[:id])
    set_seo_meta '文章修改'
  end

  def update
    @topic = Topic.find(params[:id])
    if @topic.update_attributes(params[:session])
      redirect_to '/topics/category/1', notice: '修改成功'
    else
      redirect_referrer_or_defautl default
    end
  end

  def destory
    if Topic.delete(params[:id])
      redirect_to '/topics/category/1', notice: '删除成功'
    else
      redirect_referrer_or_default default
    end  
  end

  def category
    @topics = Topic.where("category='#{params[:id]}'").paginate(:page => params[:page], :per_page => '2')
    set_seo_meta '分类浏览'
  end

end
